package com.dxf.redis.pubsub;

import com.dxf.redis.pubsub.CustomPublishJedis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class JedisPusMain {

    public static void main(String[] args) throws InterruptedException {

        ExecutorService executorService = Executors.newFixedThreadPool(5);
        JedisPoolConfig config = new JedisPoolConfig();

        config.setMaxTotal(100);

        config.setTestOnBorrow(false);

        config.setMaxWaitMillis(2000);

        JedisPool jedisPool = new JedisPool(config, "192.168.10.113", 6379);

        Jedis jedis = jedisPool.getResource();




        //Jedis jedis = new Jedis("", 6379,10000);

        jedis.select(2);

        CustomPublishJedis test = new CustomPublishJedis("test", jedis);

        for (int i=0;i<10;i++){

            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    test.publish("hello word!!!!"+Thread.currentThread().getName());
                    test.publish("测试！！！");
                }
            };
           /* Thread thread = new Thread(runnable);
            thread.start();*/
            executorService.submit(runnable);

        }

        executorService.shutdown();




    }
}
